
check_eq(spi.setup(0, 255, 0, 0, 8, 10 * 1000 * 1000, spi.MSB, 1, 0),0,"initial spi failed")

local cs = gpio.setup(20,1)

cs(0)
spi.send(0,string.char(0x06))
cs(1)
cs(0)
spi.send(0,string.char(0x20, 0x00, 0x00, 0x05))
cs(1)
timer.mdelay(500)

local str = rtos.buildDate()

cs(0)
spi.send(0,string.char(0x06))
cs(1)
cs(0)
spi.send(0,string.char(0x02, 0x00, 0x00, 0x05)..str)
cs(1)

timer.mdelay(500)

cs(0)
spi.send(0,string.char(0x03, 0x00, 0x00, 0x05))
local r = spi.recv(0,#str)
cs(1)
check_eq(r:toHex(),str:toHex(),"flash data not right")

gpio.close(20)
spi.close(0)
